<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.savpurpose}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form prependId="false">

           <script type="text/javascript">  
                function handleSaveRequest(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgSavpurpose.hide();  
                    }  
                }
                
                function handleDeleteRequest(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlcDeletesavpurpose.hide();  
                    }  
                }
                
                function componenKeyPress(e) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if(code==13) {
                        submitSavpurpose.jq.click();
                        e.preventDefault ? e.preventDefault() : e.returnValue = false;
                        e.stopPropagation();
                    }
                }
                
            </script>  

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document"
                                     action="#{savpurposeBean.newData()}"  
                                     rendered="#{menuBean.cekButtonAccess(162,'INS;')}"
                                     oncomplete="dlgSavpurpose.show()"
                                     update="displaySavpurpose"> 
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgSavpurpose.show()"
                                     icon="ui-icon-disk" actionListener="#{savpurposeBean.openData()}"
                                     rendered="#{menuBean.cekButtonAccess(162,'OPN;')}"
                                     update="displaySavpurpose" >
                    </p:commandButton>

                    <p:commandButton type="button" value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                     onclick="dlcDeletesavpurpose.show()"
                                     update="displaySavpurpose" /> 

                    <p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/>
                </p:toolbarGroup>
            </p:toolbar>
            <br />
            <p:dataTable var="savpurpose" value="#{savpurposeBean.savpurposes}" id="dtSavpurposes"
                         selection="#{savpurposeBean.selectedData}" selectionMode="single" 
                         rowKey="#{savpurpose.savpurposeId}" sortBy="#{savpurpose.purposeName}"
                         paginator="true" rows="10" paginatorPosition="bottom">
                <p:column style="width:auto" rendered="false" >
                    <f:facet name="header">ID</f:facet>
                    <h:outputText value="#{savpurpose.savpurposeId}" />
                </p:column>
                <p:column style="width:auto" sortBy="#{savpurpose.purposeName}">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{savpurpose.purposeName}" />
                </p:column>
            </p:dataTable>
          
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlcDeletesavpurpose">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtSavpurposes" 
                                         oncomplete="handleDeleteRequest(xhr, status, args)"  
                                         actionListener="#{savpurposeBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlcDeletesavpurpose.hide()" type="button" />  
                    </f:facet>
                </h:panelGrid>  
            </p:confirmDialog> 

            <p:dialog header="#{bundle.savpurpose}" widgetVar="dlgSavpurpose" closable="true"
                      dynamic="true">
                <p:ajax event="close" listener="#{savpurposeBean.handleClose}"/>
                <h:panelGrid id="displaySavpurpose" columns="2" styleClass="addELIT">
                    <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.globalName} :" />
                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{savpurposeBean.unsaveData!=null}">
                        <p:inputText value="#{savpurposeBean.unsaveData.purposeName}" 
                                 label="#{bundle.globalName}" style="width: 150px;"
                                 required="true" onkeydown="componenKeyPress(event)" id="purposeName1" >
                        <p:ajax update="msgpurposeName1" process="@this"/>
                        </p:inputText>  
                        <p:message id="msgpurposeName1" for="purposeName1" display="icon" />
                    </h:panelGrid>  
                </h:panelGrid>
                
                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{savpurposeBean.save()}"
                                         update="dtSavpurposes" widgetVar="submitSavpurpose"
                                         oncomplete="handleSaveRequest(xhr, status, args)"/>
                        <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgSavpurpose.hide()" icon="ui-icon-document"
                                         process="@this">
                            <pe:resetEditableValues for="displaySavpurpose"/>  
                        </p:commandButton>
                    </f:facet>
                </h:panelGrid>
            </p:dialog> 
        </h:form>
        </ui:composition>    
    </h:body>
</html>